package com.xoa.controller.performance;

import com.xoa.model.performance.*;
import com.xoa.model.scoreflowitem.ScoreFlowItem;
import com.xoa.model.users.Users;
import com.xoa.service.performance.ScoreSelfDataService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.session.SessionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/ScoreSelfDataController")
/**
 * 自评
 */
public class ScoreSelfDataController {
    @Autowired
    private ScoreSelfDataService scoreSelfDataService;
    //被考核人自评页面
    @RequestMapping("/scoreSelfData")
    public String scoreSelfData() {
        return "app/hr/assessmented";
    }

    /**
     * 郭心雨
     * 2018.06.25
     * 添加个人评价
     * @param scoreSelfData
     * @return
     */
    @RequestMapping("/addScoreSelfData")
    @ResponseBody
    public ToJson addScoreSelfData(ScoreSelfDataWithBLOBs scoreSelfData){
        return scoreSelfDataService.addScoreSelfData(scoreSelfData);
    }

    /**
     * 郭心雨
     * 2018.06.25
     * 删除个人评价
     * @param sid
     * @return
     */
    @RequestMapping("/delScoreSelfData")
    @ResponseBody
    public ToJson delScoreSelfData(Integer sid){
        return scoreSelfDataService.delScoreSelfData(sid);
    }

    /**
     * 郭心雨
     * 2018.06.25
     * 修改个人评价
     * @param scoreSelfData
     * @return
     */
    @RequestMapping("/modifyScoreSelfData")
    @ResponseBody
    public ToJson modifyScoreSelfData(ScoreSelfDataWithBLOBs scoreSelfData){
        return scoreSelfDataService.modifyScoreSelfData(scoreSelfData);
    }

    /**
     * 郭心雨
     * 2018.06.25
     * 查看个人评价
     * @param scoreSelfData
     * @param page
     * @param pageSize
     * @param useFlag
     * @return
     */
    @RequestMapping("/selScoreSelfData")
    @ResponseBody
    public ToJson selScoreSelfData(ScoreSelfDataWithBLOBs scoreSelfData,@RequestParam(value = "page",required = false) Integer page,
                                   @RequestParam(value = "pageSize",required = false) Integer pageSize,
                                   @RequestParam(value="useFlag",required = false) Boolean useFlag){
        return scoreSelfDataService.selScoreSelfData(scoreSelfData,page,pageSize,useFlag);
    }

    //jiazhimin
    @RequestMapping("/saveSelScore")
    @ResponseBody
    public ToJson saveSelScore(HttpServletRequest request, String jsonStr){

        return scoreSelfDataService.saveSelScore(request,jsonStr);
    }
    @ResponseBody
    @RequestMapping("/getScoreFlowItemByFlowId")
    public ToJson<ScoreFlowItem> getScoreFlowItemByFlowId(HttpServletRequest request, ScoreFlowItem scoreFlowItem){
        Cookie redisSessionId = CookiesUtil.getCookieByName(request,"redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(),Users.class,new Users(),redisSessionId);
        scoreFlowItem.setExaminer(user.getUserId());
        scoreFlowItem.setExaminerStr(user.getUserName());
        return scoreSelfDataService.getScoreFlowItemByFlowId(scoreFlowItem);
    }
    //考核情况
    @ResponseBody
    @RequestMapping("/getKaohe")
    public ToJson<ScoreFlowItem> getKaohe(ScoreFlowItem scoreFlow){
        return scoreSelfDataService.getKaohe(scoreFlow);
    }
    //考核人列表
    @ResponseBody
    @RequestMapping("/getKaoheRenList")
    public ToJson getKaoheRenList(int flowId){
        return scoreSelfDataService.getKaoheRenList(flowId);
    }

    //判断是否已经考核
    @ResponseBody
    @RequestMapping("/getIsKaohe")
    public ToJson getIsKaohe(HttpServletRequest request, ScoreFlowItem scoreFlowItem){
        Cookie redisSessionId = CookiesUtil.getCookieByName(request,"redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(),Users.class,new Users(),redisSessionId);
        scoreFlowItem.setExaminer(user.getUserId());
        scoreFlowItem.setExaminerStr(user.getUserName());
        return scoreSelfDataService.getIsKaohe(scoreFlowItem);
    }

    //点击分类，判断自评情况
    @ResponseBody
    @RequestMapping("/getScoreFlowItemByZiPing")
    public ToJson<ScoreFlowItem> getScoreFlowItemByZiPing(ScoreFlowItem scoreFlowItem,String type){
        return scoreSelfDataService.getScoreFlowItemByZiPing(scoreFlowItem,type);
    }


}
